package com.wfuhui.modules.hospital.api;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wfuhui.common.annotation.AuthIgnore;
import com.wfuhui.common.utils.R;
import com.wfuhui.modules.hospital.entity.RegisterEntity;
import com.wfuhui.modules.hospital.service.RegisterService;

@RestController
@RequestMapping("/api/register/")
public class ApiRegisterController {
	
	@Autowired
	private RegisterService registerService;
	
	@AuthIgnore
    @GetMapping("list")
    public R list(@RequestParam Map<String, Object> params) {
    	List<RegisterEntity> registerList = registerService.queryList(params);
    	return R.ok().put("registerList", registerList);
    }
	
	@GetMapping("mylist")
    public R mylist(@RequestParam Map<String, Object> params, @RequestAttribute Long userId) {
		params.put("userId", userId);
    	List<RegisterEntity> registerList = registerService.queryList(params);
    	return R.ok().put("registerList", registerList);
    }
	
	@PostMapping("save")
    public R save(@RequestBody RegisterEntity register, @RequestAttribute Long userId) {
		register.setUserId(userId);
		register.setCreateTime(new Date());
    	registerService.save(register);
    	return R.ok().put("id", register.getId());
    }
	
	@GetMapping("delete")
	public R delete(Integer id) {
		registerService.delete(id);
		return R.ok();
	}
}
